package com.cloud.core.utils;



import com.cloud.core.R;

import java.util.ArrayList;

/**
 * Created by Tanghaibo
 * 2018/7/16
 * description:数字语音文件类
 */

public class VoiceSourceUtils {
    private static int[] numVoice = new int[]{R.raw.number_0, R.raw.number_1, R.raw.number_2,
            R.raw.number_3, R.raw.number_4, R.raw.number_5, R.raw.number_6,
            R.raw.number_7, R.raw.number_8, R.raw.number_9};

    public static Integer[] formatNumVoice(int num) {
        if (num > 999 || num < 0) {
            return new Integer[]{R.raw.number_0};
        }

        if (num < 10) {
            return new Integer[]{numVoice[num]};
        }
        char[] chars = String.valueOf(num).toCharArray();
        ArrayList<Integer> sourceList = new ArrayList<>();
        if (chars.length == 2) {
            if (NumberUtils.getInteger(chars[0]) > 1) {
                sourceList.add(numVoice[NumberUtils.getInteger(chars[0])]);
            }
            sourceList.add(R.raw.number_10);
            if (NumberUtils.getInteger(chars[1]) != 0) {
                sourceList.add(numVoice[NumberUtils.getInteger(chars[1])]);
            }
        } else if (chars.length == 3) {
            sourceList.add(numVoice[NumberUtils.getInteger(chars[0])]);
            sourceList.add(R.raw.number_100);
            sourceList.add(numVoice[NumberUtils.getInteger(chars[1])]);
            if (NumberUtils.getInteger(chars[1]) != 0){
                sourceList.add(R.raw.number_10);
            }
            if (NumberUtils.getInteger(chars[2]) != 0){
                sourceList.add(numVoice[NumberUtils.getInteger(chars[2])]);
            }
        }
        int size = sourceList.size();
        return sourceList.toArray(new Integer[size]);
    }
}
